﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.UI.DataVisualization.Charting;
using System.Drawing;
using HZ.Supervise.Model;
using System.Data.Sql; 
namespace HZ.Supervise.Web.Secondphase.ReportSort
{
    public partial class AreaSortInfo : BasePage
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            BindList();
            BindChart();
        }
        void BindList()
        {
            SuperviseQuery sq = new SuperviseQuery();
           
            int t = 0;
            HZ.Supervise.IBLL.IExecuteContext ie = HZ.Supervise.BLLFactory.ExecuteContext();
            ie.QueryObject = new HZ.Supervise.Model.QueryObject()
            {
                //分组字段
                GroupField = GroupByField.PurchaseTimeMonth | GroupByField.SortSource|GroupByField.SortID,
                //查询条件
                Query = sq,
                //分组查询字段
                GroupSelectField = GroupFields.PurchaseAmountTotal | GroupFields.WareHouseRate | GroupFields.WareHouseAmountTotal | GroupFields.WareHouseCountTotal | GroupFields.PurchaseCountTotal | GroupFields.DistributeRate,
                //排序字段
                SortField = "PurchaseTimeMonth ASC"
            };

            //将数据填入gridview中
            System.Data.DataTable dt = ie.ExecutePage(1,0, out t);
           
             if (dt != null && dt.Rows.Count > 0)
             {
                 ldshow.Text = Common.TableGetHtml.GetTableHtml(dt,0);
             }

 
        }
     

        protected void BindChart()
        {
            #region 左图


            int[] test = { 10000, 7000, 4000, 3000, 8000, 6000, 5000, 9900, 5000, 9000, 9900, 8800 }; //基本药品采购金额
            int[] test1 = { 3000, 1500, 1200, 10000, 10000, 30000, 10000, 20000, 11000, 20000, 20000, 14000 };  //基本药品采购数量
            int[] test2 = { 1000000, 2800000, 22000000, 33000000, 11000000, 16000000, 1000000, 11000000, 21000000, 22000000, 22000000, 28000000 };  //非基本药品采购金额
            int[] test3 = { 33000000, 1000000, 11000000, 22000000, 11000000, 18000000, 1200000, 33000000, 33000000, 33000000, 2020000, 2200000 };  //非基本药品采购数量
            string[] test4 = { "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月" };  //月份
            //***************** 非基本药品金额 柱状  *******************/
            Series series6 = new Series("非基本药品采购金额 (左刻度) 单位：万元");
            series6.ChartType = SeriesChartType.Column;
            series6.BorderWidth = 1;
            series6.ShadowOffset = 1;
            series6.Color = Color.Green;
            for (int i = 0; i < test.Length; i++) //添加数据
            {
                series6.Points.AddY(test[i]);//
                //if (i % 2 != 0)
                //{
                //    series6.Points.AddXY(dtSource.Rows[i]["PurchaseTimeMonth"].ToString().Substring(4) + "月", (double.Parse(dtSource.Rows[i]["WareHouseAmountTotal"].ToString()) / 10000).ToString());
                //}

            }
            series6.IsValueShownAsLabel = false;
            ChartHospital.Series.Add(series6);
            ChartHospital.Series["非基本药品采购金额 (左刻度) 单位：万元"].ChartArea = "ChartAreaColumn";
            ChartHospital.ChartAreas["ChartAreaColumn"].AxisX.MajorGrid.Interval = 1;

            //***************** 基本药品金额 柱状  *******************/
            Series series7 = new Series("基本药品采购金额 (左刻度) 单位：万元");
            series7.ChartType = SeriesChartType.Column;
            series7.BorderWidth = 1;
            series7.ShadowOffset = 1;
            series7.Color = Color.Red;
            for (int i = 0; i < test2.Length; i++) //添加数据
            {
                series7.Points.AddXY(test4[i], test1[i]);
                //if (i % 2 == 0)
                //{
                //    series7.Points.AddXY(dtSource.Rows[i]["PurchaseTimeMonth"].ToString().Substring(4) + "月", (double.Parse(dtSource.Rows[i]["WareHouseAmountTotal"].ToString()) / 10000).ToString());
                //}

            }
            series7.IsValueShownAsLabel = false;
            ChartHospital.Series.Add(series7);
            ChartHospital.Series["基本药品采购金额 (左刻度) 单位：万元"].ChartArea = "ChartAreaColumn";
            ChartHospital.ChartAreas["ChartAreaColumn"].AxisX.MajorGrid.Interval = 1;
            //给chart赋值
            //***********************基本药品数量 曲线******************/
            Series series5 = new Series("基本药品采购数量 (左刻度) 单位：个");
            series5.ChartType = SeriesChartType.Spline;
            series5.BorderWidth = 1;
            series5.ShadowOffset = 1;
            for (int i = 0; i < test3.Length; i++) //添加数据
            {
                series5.Points.AddY(test2[i]);
                //if (i % 2 == 0)
                //{
                //    series5.Points.AddXY(dtSource.Rows[i]["PurchaseTimeMonth"].ToString().Substring(4) + "月", dtSource.Rows[i]["WareHouseCountTotal"].ToString());
                //}

            }

            series5.IsValueShownAsLabel = false;
            ChartHospital.Series.Add(series5);
            ChartHospital.Series["基本药品采购数量 (左刻度) 单位：个"].MarkerStyle = MarkerStyle.Diamond;    //设置点标记样式(此为圆点)
            ChartHospital.Series["基本药品采购数量 (左刻度) 单位：个"].MarkerSize = 8;    //设置线节点大小
            ChartHospital.Series["基本药品采购数量 (左刻度) 单位：个"].ChartArea = "ChartAreaLine";

            //***********************非基本药品数量 曲线******************/
            Series series8 = new Series("非基本药品采购数量 (左刻度) 单位：个");
            series8.ChartType = SeriesChartType.Spline;
            series8.BorderWidth = 1;
            series8.ShadowOffset = 1;
            for (int i = 0; i < test3.Length; i++) //添加数据
            {
                series8.Points.AddXY(test4[i], test3[i]);
                //if (i % 2 != 0)
                //{
                //    series8.Points.AddXY(dtSource.Rows[i]["PurchaseTimeMonth"].ToString().Substring(4) + "月", dtSource.Rows[i]["WareHouseCountTotal"].ToString());
                //}

            }

            series8.IsValueShownAsLabel = false;
            ChartHospital.Series.Add(series8);
            ChartHospital.Series["非基本药品采购数量 (左刻度) 单位：个"].MarkerStyle = MarkerStyle.Diamond;    //设置点标记样式(此为圆点)
            ChartHospital.Series["非基本药品采购数量 (左刻度) 单位：个"].MarkerSize = 8;    //设置线节点大小
            ChartHospital.Series["非基本药品采购数量 (左刻度) 单位：个"].ChartArea = "ChartAreaLine";

            Title t3 = new Title("安徽省采购情况");            //图片标题

            ChartHospital.Titles.Add(t3);
            ChartHospital.Width = (1 * 20 + 200) >= 400 ? 600 : 600;    //图片宽度
            ChartHospital.Height = 500;                      //图片高度

            //作图区的显示属性设置
            ChartHospital.ChartAreas["ChartAreaColumn"].AxisX.IsMarginVisible = true;
            ChartHospital.ChartAreas["ChartAreaColumn"].Area3DStyle.Enable3D = false;

            ChartHospital.ChartAreas["ChartAreaLine"].AxisX.IsMarginVisible = true;
            ChartHospital.ChartAreas["ChartAreaLine"].Area3DStyle.Enable3D = false;
            //背景色设置
            ChartHospital.ChartAreas["ChartAreaColumn"].ShadowColor = Color.Transparent;
            ChartHospital.ChartAreas["ChartAreaColumn"].BackColor = Color.White;         //该处设置为了由天蓝到白色的逐渐变化
            ChartHospital.ChartAreas["ChartAreaColumn"].BackGradientStyle = GradientStyle.TopBottom;
            ChartHospital.ChartAreas["ChartAreaColumn"].BackSecondaryColor = Color.White;

            ChartHospital.ChartAreas["ChartAreaLine"].ShadowColor = Color.Transparent;
            ChartHospital.ChartAreas["ChartAreaLine"].BackColor = Color.White;         //该处设置为了由天蓝到白色的逐渐变化
            ChartHospital.ChartAreas["ChartAreaLine"].BackGradientStyle = GradientStyle.TopBottom;
            ChartHospital.ChartAreas["ChartAreaLine"].BackSecondaryColor = Color.White;
            //X,Y坐标线颜色和大小
            ChartHospital.ChartAreas["ChartAreaColumn"].AxisX.LineColor = Color.Blue;
            ChartHospital.ChartAreas["ChartAreaColumn"].AxisY.LineColor = Color.Blue;

            ChartHospital.ChartAreas["ChartAreaColumn"].AxisX.LineWidth = 1;
            ChartHospital.ChartAreas["ChartAreaColumn"].AxisY.LineWidth = 1;

            ChartHospital.ChartAreas["ChartAreaColumn"].AxisY.Title = "交易金额（万元）";
            ChartHospital.ChartAreas["ChartAreaColumn"].AxisX.Title = "交易日期";


            ChartHospital.ChartAreas["ChartAreaColumn"].AxisY.Maximum = 30000;
            ChartHospital.ChartAreas["ChartAreaColumn"].AxisY.Minimum = 0;
            ChartHospital.ChartAreas["ChartAreaColumn"].AxisY.Interval = 4000;

            //*******曲线*************************************************************/
            ChartHospital.ChartAreas["ChartAreaLine"].AxisX.LineColor = Color.Blue;
            ChartHospital.ChartAreas["ChartAreaLine"].AxisY.LineColor = Color.Blue;

            ChartHospital.ChartAreas["ChartAreaLine"].AxisX.LineWidth = 1;
            ChartHospital.ChartAreas["ChartAreaLine"].AxisY.LineWidth = 1;

            ChartHospital.ChartAreas["ChartAreaLine"].AxisY.Title = "交易数量（个）";
            ChartHospital.ChartAreas["ChartAreaLine"].AxisX.Title = "交易日期";


            ChartHospital.ChartAreas["ChartAreaLine"].AxisY.Maximum = 40000000;
            ChartHospital.ChartAreas["ChartAreaLine"].AxisY.Minimum = 0;
            ChartHospital.ChartAreas["ChartAreaLine"].AxisY.Interval = 10000000;


            //中间X,Y线条的颜色设置
            ChartHospital.ChartAreas["ChartAreaLine"].AxisX.MajorGrid.LineColor = Color.Blue;
            ChartHospital.ChartAreas["ChartAreaLine"].AxisY.MajorGrid.LineColor = Color.Blue;

            ChartHospital.ChartAreas["ChartAreaColumn"].AxisX.MajorGrid.LineColor = Color.Blue;
            ChartHospital.ChartAreas["ChartAreaColumn"].AxisY.MajorGrid.LineColor = Color.Blue;
            ////X.Y轴数据显示间隔
            //ChartHospital.ChartAreas["ChartArea1"].AxisX.Interval = 1;  //X轴数据显示间隔
            //ChartHospital.ChartAreas["ChartArea1"].AxisY.Interval = dtSource.Rows.Count;
            //X轴线条显示间隔

            ChartHospital.ChartAreas["ChartAreaColumn"].AxisX.IntervalOffset = 1;
            ChartHospital.ChartAreas["ChartAreaColumn"].AxisX.Interval = 1;
            ChartHospital.ChartAreas["ChartAreaLine"].AxisX.IntervalOffset = 1;
            ChartHospital.ChartAreas["ChartAreaLine"].AxisX.Interval = 1;


            ChartHospital.ChartAreas["ChartAreaColumn"].AxisX.MajorGrid.Interval = 1;
            ChartHospital.ChartAreas["ChartAreaLine"].AxisX.MajorGrid.Interval = 1;

            //lblInAmount.Text = "111";
            //lblInCompany_Jy.Text = "222";
            //lblInCompany_Ps.Text = "333";
            //lblInCompany_Sc.Text = "4444";
            //lblInCount.Text = "55555";
            //lblInDrugNum.Text = "666";
            //lblInhospitalNum.Text = "777";
            //lblInProductNum.Text = "8888";

            #endregion 
            
        }
        protected void gvwSortInfo_RowCreated(object sender, GridViewRowEventArgs e)
        {
            #region 合并表头
            switch (e.Row.RowType)
            {
                case DataControlRowType.Header:

                    //取得下拉框的月份


                    //第一行表头
                    TableCellCollection tcHeader = e.Row.Cells;
                    tcHeader.Clear();
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[0].Attributes.Add("colspan", "2"); //跨Row
                    tcHeader[0].Attributes.Add("bgcolor", "LightSteelBlue");
                    //tcHeader[0].Attributes.Add("bgcolor", "white");
                    tcHeader[0].Text = "";
                    //tcHeader.Add(new TableHeaderCell());
                    //tcHeader[1].Attributes.Add("bgcolor", "Red");
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[1].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[1].Text = "1月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[2].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[2].Text = "2月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[3].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[3].Text = "3月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[4].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[4].Text = "4月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[5].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[5].Text = "5月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[6].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[6].Text = "6月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[7].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[7].Text = "7月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[8].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[8].Text = "8月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[9].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[9].Text = "9月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[10].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[10].Text = "10月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[11].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[11].Text = "11月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[12].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[12].Text = "12月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[13].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[13].Text = "</th></tr><tr>";



                    //第2行表头
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[14].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[14].Text = "类别";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[15].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[15].Text = "是否基药";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[16].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[16].Text = "采购总金额";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[17].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[17].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[18].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[18].Text = "采购总金额";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[19].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[19].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[20].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[20].Text = "采购总金额";
                    tcHeader.Add(new TableHeaderCell());

                    tcHeader[21].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[21].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[22].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[22].Text = "采购总金额";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[23].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[23].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[24].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[24].Text = "采购总金额";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[25].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[25].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[26].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[26].Text = "采购总金额";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[27].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[27].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[28].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[28].Text = "采购总金额";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[29].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[29].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[30].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[30].Text = "采购总金额";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[31].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[31].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[32].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[32].Text = "采购总金额";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[33].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[33].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[34].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[34].Text = "采购总金额";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[35].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[35].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[36].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[36].Text = "采购总金额";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[37].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[37].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[38].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[38].Text = "采购总金额";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[39].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[39].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[40].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[40].Text = "操作</th></tr><tr>";
                    break;
            }
            #endregion
        }
    

    }
}
